﻿using System;
using System.DirectoryServices;
using System.Collections;
using System.Collections.Generic;

namespace SBPweb.MediaCenter.Common.Security
{
    public class ActiveDirectoryHandler
    {
        public static List<DirectoryEntry> EnumerateGroups(string groupName)
        {
            List<DirectoryEntry> ret = new List<DirectoryEntry>();
            DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName);
            DirectoryEntry admGroup = localMachine.Children.Find(groupName, "group");
            object members = admGroup.Invoke("members", null);

            foreach (object groupMember in (IEnumerable)members)
            {
                ret.Add(new DirectoryEntry(groupMember));
            }

            return ret;
        }
    }
}